package com.yz.lzq.liwushuo.ui.modules.home.nomal;

import android.content.Context;

import com.yz.lzq.liwushuo.config.NumberUtil;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.HomeBoutiqueRecycleBean;
import com.yz.lzq.liwushuo.ui.modules.comminterface.OnGetSharedPerfenceDataListener;
import com.yz.lzq.liwushuo.ui.setting.SettingActivityPresenter;

/**
 * Created by Administrator on 2016/12/13.
 * home页面的精品fragment的中间人模块
 */

public class HomeNomalPresenter {
    private HomeNomalContract.HomeNomalViewInterface viewInterface = null;
    private HomeNomalContract.HomeNomalModelInterface modelInterface = null;
    //用户身份设置功能模块的中间人层对象，用于获取用户信息
    private SettingActivityPresenter settingActivityPresenter = null;
    private int mOffSet = 0;

    public HomeNomalPresenter(Context context) {
        modelInterface = new HomeNomalModel();
        settingActivityPresenter = new SettingActivityPresenter(context);
    }

    private int currentOffset = 20;

    public HomeNomalPresenter(Context context, HomeNomalContract.HomeNomalViewInterface viewInterface) {
        this.viewInterface = viewInterface;
        modelInterface = new HomeNomalModel();
        settingActivityPresenter = new SettingActivityPresenter(context);
    }


    /**
     * 请求数据展示RecyclerView视图
     */
    public void showRecycleView(final boolean loadMore) {

        settingActivityPresenter.setOnGetUserSharedPerfence(new OnGetSharedPerfenceDataListener() {
            @Override
            public void onGetGenderAndGenration(int gender, int genration) {
                if (loadMore) {
                    mOffSet += 20;
                } else {
                    mOffSet = 0;
                }
                modelInterface.LoadHomeNomalRecycleViewBean(0, viewInterface.getFragmentID(), gender, genration, NumberUtil.LIMIT, mOffSet, new OnGetNetDataListener<HomeBoutiqueRecycleBean>() {
                    @Override
                    public void onGetDataSucess(HomeBoutiqueRecycleBean data) {
                        currentOffset = 0;
                        viewInterface.getHomeJingPinRecycleBean(data);
                    }

                    @Override
                    public void onGetDataFalied(Throwable t) {

                    }
                }, loadMore);
            }
        });
    }

}
